home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Burning & Media
/
GB-PVR 1.2.13
/
GBPVR10213.msi
/
Cabs.w1.cab
/
ExtendedEWA.cs677
< prev
next >
Wrap
Text File
|
2008-03-01
|
5KB
|
173 lines
using System;
using System.Collections;
using System.Data.Common;
using System.Data.SQLite;
using System.IO;
using System.Web;
namespace gbweb
{
public class ExtendedEWA
{
public enum Role
{
Actor = 1,
Director = 2,
Producer = 3,
Writer = 4,
ExecProducer = 5,
GuestStar = 6,
Host = 7,
Narrator = 9,
Judge = 10,
Contestant = 11,
Guest = 12
}
private static string databaseFileName;
private static DbConnection ExtendedEWAConnection
{
get
{
return HttpContext.Current.Items["ExtendedEWAConnection"] as DbConnection;
}
set
{
HttpContext.Current.Items["ExtendedEWAConnection"] = value;
}
}
// TODO: All these statics are creating a race condition on page processing
public static bool Initialize()
{
if (databaseFileName == null)
{
databaseFileName = Path.Combine(Global.Settings.GetInstallDir(), "ExtendedEWA.db3");
}
return File.Exists(databaseFileName);
}
public static void OpenExtendedEWADB()
{
if (File.Exists(Path.Combine(Global.Settings.GetInstallDir(), "ExtendedEWA.db3")))
{
DbProviderFactory ExtendedEWAFactory = new SQLiteFactory();
ExtendedEWAConnection = ExtendedEWAFactory.CreateConnection();
ExtendedEWAConnection.ConnectionString = "Data Source=" + databaseFileName + ";Version=3;New=True";
}
else
{
DbProviderFactory ExtendedEWAFactory = DbProviderFactories.GetFactory("System.Data.OleDb");
ExtendedEWAConnection = ExtendedEWAFactory.CreateConnection();
ExtendedEWAConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + databaseFileName;
}
ExtendedEWAConnection.Open();
}
public static void CloseExtendedEWADB()
{
ExtendedEWAConnection.Close();
}
public static bool IsNew(string UniqueProgrammeIdentifier)
{
byte isNew = 0;
// create the command object and store the sql query
DbCommand aCommand = ExtendedEWAConnection.CreateCommand();
aCommand.CommandText = "select new_show from Schedule where scheduleid='" + UniqueProgrammeIdentifier + "'";
aCommand.Connection = ExtendedEWAConnection;
DbDataReader aReader = aCommand.ExecuteReader();
// read from the database
if (aReader.Read())
{
isNew = aReader.GetByte(0);
}
// close the reader
aReader.Close();
return isNew != 0;
}
public static bool IsHD(string UniqueProgrammeIdentifier)
{
byte isHDValue = 0;
// create the command object and store the sql query
DbCommand aCommand = ExtendedEWAConnection.CreateCommand();
aCommand.CommandText = "select hd from Schedule where scheduleid='" + UniqueProgrammeIdentifier + "'";
aCommand.Connection = ExtendedEWAConnection;
DbDataReader aReader = aCommand.ExecuteReader();
// read from the database
if (aReader.Read())
{
isHDValue = aReader.GetByte(0);
}
// close the reader
aReader.Close();
return isHDValue != 0;
}
public static string[] GetProgramInfo(string UniqueProgrammeIdentifier)
{
string[] programInfo = new string[] {};
// create the command object and store the sql query
DbCommand aCommand = ExtendedEWAConnection.CreateCommand();
aCommand.CommandText = "select year_released,air_date,star_rating from ProgramData where program_id='" + UniqueProgrammeIdentifier + "'";
aCommand.Connection = ExtendedEWAConnection;
DbDataReader aReader = aCommand.ExecuteReader();
// read from the database
if (aReader.Read())
{
programInfo = new string[] {
Convert.ToString(aReader.GetInt32(0)),
aReader.GetString(1),
aReader.GetString(2)};
}
// close the reader
aReader.Close();
return programInfo;
}
public static ArrayList GetCast(string UniqueProgrammeIdentifier)
{
ArrayList list = new ArrayList();
// create the command object and store the sql query
DbCommand aCommand = ExtendedEWAConnection.CreateCommand();
aCommand.CommandText = "select DISTINCT givenname,surname,role FROM Crew where program_id='" + UniqueProgrammeIdentifier + "' ORDER BY role";
aCommand.Connection = ExtendedEWAConnection;
DbDataReader aReader = aCommand.ExecuteReader();
// iterate through the database
while(aReader.Read())
{
Crew crew = new Crew();
crew.GivenName = aReader.GetString(0);
crew.SurName = aReader.GetString(1);
crew.Role = (Role)aReader.GetByte(2);
list.Add(crew);
}
// close the reader
aReader.Close();
return list;
}
public struct Crew
{
public string GivenName;
public string SurName;
public Role Role;
}
}
}